﻿function openSelectDialog(option) {
    // code 为弹窗编码
    // type 为选择类型 0为列表单选，1为列表多选，2为树多选，3为树单选
    // rowIndex 为当前页面有多个弹出框的时候进行区分
    // param 默认查询参数，JSON格式，在sql语句Xml写对应的判断语句
    var defaultOption = {
        el: "#selectControl",
        type: 0,
        host: "",
        code: "",
        index: 0,
        width: "800px",
        height: "500px",
        resultCallback: "",
        callback: {
            close: function () {

            }
        }
    }

    defaultOption = $.extend(true, defaultOption, option);

    var url = GetLocationUrl(defaultOption.host + '/customsearch/select');// 列表多选
    var ids = "";
    $(":input").each(function (a, b) {
        var name = $(b).attr("sysSelectResultName");
        if (typeof (name) != "undefined") {
            var len = name.indexOf("result1");
            if (len > -1) {
                if (index) {
                    len = name.indexOf("_" + defaultOption.index);
                    if (len > 0) {
                        ids = $(b).val();
                    }
                } else {
                    ids = $(b).val();
                }
            }
        }
    });

    url += "?code=" + defaultOption.code + "&pageNum=" + defaultOption.type + (ids == "" ? "" : "&arg=," + ids + ",");
    if (defaultOption.resultCallback) {
        url += "&resultcallback=" + defaultOption.resultCallback;
    }


    if (defaultOption.param) {
        url += "&isfirst=is&defaultParam=" + encodeURI(encodeURI(defaultOption.param));
    }

    var option = {
        type: 2,
        title: '弹框选择',
        shadeClose: true,
        shade: 0.8,
        area: [defaultOption.width, defaultOption.height],
        content: url,
        end: defaultOption.callback.close
    }

    $(defaultOption.el).click(function () {
        index = defaultOption.index;
        layer.open(option);
    });
}